﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace JaxDug.Helpers
{
    public static class ObjectExtensions
    {
        /// <summary>
        /// http://ideone.com/1AQvO#
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static  TResult MapUsingSerializer<T, TResult>(this T source)
        {
            var j = new JavaScriptSerializer();
            var s = j.Serialize(source);
            return j.Deserialize<TResult>(s);
        }
    }
}